package han.cirno.corrupt.util

import han.cirno.corrupt.Application

object DensityUtil {
    fun dp2px(dpValue: Float): Int {
        val scale = Application.getApplicationContext().applicationContext.resources
            .displayMetrics.density
        return (dpValue * scale + 0.5f).toInt()
    }

    fun px2dp(pxValue: Float): Int {
        val scale = Application.getApplicationContext().applicationContext.resources
            .displayMetrics.density
        return (pxValue / scale + 0.5f).toInt()
    }

    fun deviceWidthPX(): Int {
        return Application.getApplicationContext().applicationContext.resources
            .displayMetrics.widthPixels
    }

    fun deviceHeightPX(): Int {
        return Application.getApplicationContext().applicationContext.resources
            .displayMetrics.heightPixels
    }
}
